<template>
	<view>
		<u--form :model="inputForm" labelWidth="100px" class="u-form" labelPosition="left" :rules="rules"
			ref="inputForm">
			<u-form-item label="姓名" borderBottom prop="name">
				<u--input placeholder='请填写姓名' disabled v-model="inputForm.name" border="none"></u--input>
			</u-form-item>
			<u-form-item label="订单号" borderBottom prop="orderNo" @click="inputOrder()">
				<u--input placeholder='请填写订单号' v-model="inputForm.orderNo" border="none"></u--input>
			</u-form-item>
			<u-form-item label="款号" borderBottom prop="styleNo">
				<u--input placeholder='请填写订单号' v-model="inputForm.styleNo" border="none"></u--input>
			</u-form-item>
			<u-form-item label="信息集" borderBottom prop="picUrl">
				<jp-image-upload v-model="inputForm.picUrl" :disabled="false"></jp-image-upload>
			</u-form-item>
			
	<!-- 		<u-form-item label="信息集" borderBottom prop="fileList">
				<jp-form-upload v-model="inputForm.fileList" :disabled="false"></jp-form-upload>
			</u-form-item> -->
			
		</u--form>
		<view class="bottom-wrap flex">
			<u-button type="primary" text=提交 @click="formSubmit"></u-button>
		</view>
	</view>
</template>

<script>
	import * as $auth from "@/common/auth"
	import customerMobileService from '@/api/test/customer/testCustomerLeaveService'
	export default {
		data() {
			return {
				inputForm: {
					id: '',
					name: '',
					phone: '',
					orderNo: '',
					picUrl: '',
					styleId: '',
					styleNo: '',
					orderId: '',
					
					fileList: []
				},
				rules: {
					'name': [{
						required: true,
						message: '姓名不能为空',
						trigger: ['blur', 'change']
					}],
				}
			}
		},
		async onLoad(query) {
			if (query && query.id) {
				uni.setNavigationBarTitle({
					title: "修改客户信息"
				});
				let data = await customerMobileService.queryById(query.id)
				this.inputForm = this.recover(this.inputForm, data)
			} else {
				var userInfo = uni.getStorageSync('userInfo');
				this.inputForm.name = userInfo.name;
				this.inputForm.phone = userInfo.phone;
				uni.setNavigationBarTitle({
					title: "新建客户信息"
				});
			}
		},
		methods: {
			inputOrder() {
				uni.navigateTo({
					url: '/pages/subA/test/customer/CustomerOrderForm',
					events: {
						acceptOrderData: this.handleOrderSelect
					}
				})
			},
			handleOrderSelect(data) {
				//同步数据
				this.inputForm.orderId = data.orderId;
				this.inputForm.orderNo = data.orderNo;
				this.inputForm.styleId = data.styleId;
				this.inputForm.styleNo = data.styleNo;
			},
			formSubmit: function(e) {
				//定义表单规则
				this.$refs.inputForm.validate().then(res => {
					uni.showLoading()
					customerMobileService.save(this.inputForm).then((data) => {
						uni.showToast({
							title: data,
							icon: "success"
						});
						uni.navigateTo({
							url: '/pages/subA/test/customer/CustomerMobileList'
						})
					}).catch((e) => {

					})

				})
			}
		}
	}
</script>